PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/src/Deployment/WoWBench/BlizzardInterface/FrameXML/WorldMapFrame.lua

#
Lua | 515 lines | 447 code | 45 blank | 23 comment | 77 complexity | 474158ca8721d1416cbe9c52e852d405 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, LGPL-2.1
  1. NUM_WORLDMAP_DETAIL_TILES = 12;
  2. NUM_WORLDMAP_POIS = 0;
  3. NUM_WORLDMAP_POI_COLUMNS = 8;
  4. WORLDMAP_POI_TEXTURE_WIDTH = 128;
  5. NUM_WORLDMAP_OVERLAYS = 0;
  6. NUM_WORLDMAP_FLAGS = 2;
  7. function WorldMapFrame_OnLoad()
  8. this:RegisterEvent("PLAYER_ENTERING_WORLD");
  9. this:RegisterEvent("WORLD_MAP_UPDATE");
  10. this:RegisterEvent("CLOSE_WORLD_MAP");
  11. this:RegisterEvent("WORLD_MAP_NAME_UPDATE");
  12. this.poiHighlight = nil;
  13. this.areaName = nil;
  14. CreateWorldMapArrowFrame(WorldMapFrame);
  15. WorldMapFrame_Update();
  16. -- Hide the world behind the map when we're in widescreen mode
  17. local width = GetScreenWidth();
  18. local height = GetScreenHeight();
  19. if ( width / height < 4 / 3 ) then
  20. width = width * 1.25;
  21. height = height * 1.25;
  22. end
  23. BlackoutWorld:SetWidth( width );
  24. BlackoutWorld:SetHeight( height );
  25. end
  26. function WorldMapFrame_OnEvent()
  27. -- FIX ME FOR 1.13
  28. if ( event == "PLAYER_ENTERING_WORLD" ) then
  29. if ( this:IsVisible() ) then
  30. HideUIPanel(WorldMapFrame);
  31. end
  32. end
  33. if ( event == "WORLD_MAP_UPDATE" ) then
  34. if ( this:IsVisible() ) then
  35. WorldMapFrame_Update();
  36. end
  37. elseif ( event == "CLOSE_WORLD_MAP" ) then
  38. HideUIPanel(this);
  39. end
  40. end
  41. function WorldMapFrame_Update()
  42. local mapFileName, textureHeight = GetMapInfo();
  43. if ( not mapFileName ) then
  44. -- Temporary Hack
  45. mapFileName = "World";
  46. end
  47. for i=1, NUM_WORLDMAP_DETAIL_TILES, 1 do
  48. getglobal("WorldMapDetailTile"..i):SetTexture("Interface\\WorldMap\\"..mapFileName.."\\"..mapFileName..i);
  49. end
  50. --WorldMapHighlight:Hide();
  51. -- Enable/Disable zoom out button
  52. if ( GetCurrentMapContinent() == 0 ) then
  53. WorldMapZoomOutButton:Disable();
  54. else
  55. WorldMapZoomOutButton:Enable();
  56. end
  57. -- Setup the POI's
  58. local numPOIs = GetNumMapLandmarks();
  59. local name, description, textureIndex, x, y;
  60. local worldMapPOI;
  61. local x1, x2, y1, y2;
  62. if ( NUM_WORLDMAP_POIS < numPOIs ) then
  63. for i=NUM_WORLDMAP_POIS+1, numPOIs do
  64. WorldMap_CreatePOI(i);
  65. end
  66. NUM_WORLDMAP_POIS = numPOIs;
  67. end
  68. for i=1, NUM_WORLDMAP_POIS do
  69. worldMapPOI = getglobal("WorldMapFramePOI"..i);
  70. if ( i <= numPOIs ) then
  71. name, description, textureIndex, x, y = GetMapLandmarkInfo(i);
  72. x1, x2, y1, y2 = WorldMap_GetPOITextureCoords(textureIndex);
  73. getglobal(worldMapPOI:GetName().."Texture"):SetTexCoord(x1, x2, y1, y2);
  74. x = x * WorldMapButton:GetWidth();
  75. y = -y * WorldMapButton:GetHeight();
  76. worldMapPOI:SetPoint("CENTER", "WorldMapButton", "TOPLEFT", x, y );
  77. worldMapPOI.name = name;
  78. worldMapPOI.description = description;
  79. worldMapPOI:Show();
  80. else
  81. worldMapPOI:Hide();
  82. end
  83. end
  84. -- Setup the overlays
  85. local numOverlays = GetNumMapOverlays();
  86. local textureName, textureWidth, textureHeight, offsetX, offsetY, mapPointX, mapPointY;
  87. local textureCount = 0, neededTextures;
  88. local texture;
  89. local texturePixelWidth, textureFileWidth, texturePixelHeight, textureFileHeight;
  90. local numTexturesWide, numTexturesTall;
  91. for i=1, numOverlays do
  92. textureName, textureWidth, textureHeight, offsetX, offsetY, mapPointX, mapPointY = GetMapOverlayInfo(i);
  93. numTexturesWide = ceil(textureWidth/256);
  94. numTexturesTall = ceil(textureHeight/256);
  95. neededTextures = textureCount + (numTexturesWide * numTexturesTall);
  96. if ( neededTextures > NUM_WORLDMAP_OVERLAYS ) then
  97. for j=NUM_WORLDMAP_OVERLAYS+1, neededTextures do
  98. WorldMapDetailFrame:CreateTexture("WorldMapOverlay"..j, "ARTWORK");
  99. end
  100. NUM_WORLDMAP_OVERLAYS = neededTextures;
  101. end
  102. for j=1, numTexturesTall do
  103. if ( j < numTexturesTall ) then
  104. texturePixelHeight = 256;
  105. textureFileHeight = 256;
  106. else
  107. texturePixelHeight = mod(textureHeight, 256);
  108. if ( texturePixelHeight == 0 ) then
  109. texturePixelHeight = 256;
  110. end
  111. textureFileHeight = 16;
  112. while(textureFileHeight < texturePixelHeight) do
  113. textureFileHeight = textureFileHeight * 2;
  114. end
  115. end
  116. for k=1, numTexturesWide do
  117. textureCount = textureCount + 1;
  118. texture = getglobal("WorldMapOverlay"..textureCount);
  119. if ( k < numTexturesWide ) then
  120. texturePixelWidth = 256;
  121. textureFileWidth = 256;
  122. else
  123. texturePixelWidth = mod(textureWidth, 256);
  124. if ( texturePixelWidth == 0 ) then
  125. texturePixelWidth = 256;
  126. end
  127. textureFileWidth = 16;
  128. while(textureFileWidth < texturePixelWidth) do
  129. textureFileWidth = textureFileWidth * 2;
  130. end
  131. end
  132. texture:SetWidth(texturePixelWidth);
  133. texture:SetHeight(texturePixelHeight);
  134. texture:SetTexCoord(0, texturePixelWidth/textureFileWidth, 0, texturePixelHeight/textureFileHeight);
  135. texture:SetPoint("TOPLEFT", offsetX + (256 * (k-1)), -(offsetY + (256 * (j - 1))));
  136. texture:SetTexture(textureName..(((j - 1) * numTexturesWide) + k));
  137. texture:Show();
  138. end
  139. end
  140. end
  141. for i=textureCount+1, NUM_WORLDMAP_OVERLAYS do
  142. getglobal("WorldMapOverlay"..i):Hide();
  143. end
  144. end
  145. function WorldMapPOI_OnEnter()
  146. WorldMapFrame.poiHighlight = 1;
  147. if ( this.description and strlen(this.description) > 0 ) then
  148. WorldMapFrameAreaLabel:SetText(this.name);
  149. WorldMapFrameAreaDescription:SetText(this.description);
  150. else
  151. WorldMapFrameAreaLabel:SetText(this.name);
  152. WorldMapFrameAreaDescription:SetText("");
  153. end
  154. end
  155. function WorldMapPOI_OnLeave()
  156. WorldMapFrame.poiHighlight = nil;
  157. WorldMapFrameAreaLabel:SetText(WorldMapFrame.areaName);
  158. WorldMapFrameAreaDescription:SetText("");
  159. end
  160. function WorldMapPOI_OnClick()
  161. WorldMapButton_OnClick(arg1, WorldMapButton);
  162. end
  163. function WorldMap_CreatePOI(index)
  164. local button = CreateFrame("Button", "WorldMapFramePOI"..index, WorldMapButton);
  165. button:SetWidth(32);
  166. button:SetHeight(32);
  167. button:RegisterForClicks("LeftButtonUp", "RightButtonUp");
  168. button:SetScript("OnEnter", WorldMapPOI_OnEnter);
  169. button:SetScript("OnLeave", WorldMapPOI_OnLeave);
  170. button:SetScript("OnClick", WorldMapPOI_OnClick);
  171. local texture = button:CreateTexture(button:GetName().."Texture", "BACKGROUND");
  172. texture:SetWidth(16);
  173. texture:SetHeight(16);
  174. texture:SetPoint("CENTER", 0, 0);
  175. texture:SetTexture("Interface\\Minimap\\POIIcons");
  176. end
  177. function WorldMap_GetPOITextureCoords(index)
  178. local worldMapIconDimension = 16;
  179. local xCoord1, xCoord2, yCoord1, yCoord2;
  180. local coordIncrement = worldMapIconDimension / WORLDMAP_POI_TEXTURE_WIDTH;
  181. xCoord1 = mod(index , NUM_WORLDMAP_POI_COLUMNS) * coordIncrement;
  182. xCoord2 = xCoord1 + coordIncrement;
  183. yCoord1 = floor(index / NUM_WORLDMAP_POI_COLUMNS) * coordIncrement;
  184. yCoord2 = yCoord1 + coordIncrement;
  185. return xCoord1, xCoord2, yCoord1, yCoord2;
  186. end
  187. function WorldMapContinentsDropDown_OnLoad()
  188. UIDropDownMenu_Initialize(this, WorldMapContinentsDropDown_Initialize);
  189. UIDropDownMenu_SetWidth(130);
  190. end
  191. function WorldMapContinentsDropDown_Initialize()
  192. WorldMapFrame_LoadContinents(GetMapContinents());
  193. end
  194. function WorldMapFrame_LoadContinents(...)
  195. local info;
  196. for i=1, arg.n, 1 do
  197. info = {};
  198. info.text = arg[i];
  199. info.func = WorldMapContinentButton_OnClick;
  200. UIDropDownMenu_AddButton(info);
  201. end
  202. end
  203. function WorldMapZoneDropDown_OnLoad()
  204. this:RegisterEvent("WORLD_MAP_UPDATE");
  205. UIDropDownMenu_Initialize(this, WorldMapZoneDropDown_Initialize);
  206. UIDropDownMenu_SetWidth(130);
  207. end
  208. function WorldMapZoneDropDown_Initialize()
  209. WorldMapFrame_LoadZones(GetMapZones(GetCurrentMapContinent()));
  210. end
  211. function WorldMapFrame_LoadZones(...)
  212. local info;
  213. for i=1, arg.n, 1 do
  214. info = {};
  215. info.text = arg[i];
  216. info.func = WorldMapZoneButton_OnClick;
  217. UIDropDownMenu_AddButton(info);
  218. end
  219. end
  220. function WorldMapContinentButton_OnClick()
  221. UIDropDownMenu_SetSelectedID(WorldMapContinentDropDown, this:GetID());
  222. SetMapZoom(this:GetID());
  223. end
  224. function WorldMapZoneButton_OnClick()
  225. UIDropDownMenu_SetSelectedID(WorldMapZoneDropDown, this:GetID());
  226. SetMapZoom(GetCurrentMapContinent(), this:GetID());
  227. end
  228. function WorldMapZoomOutButton_OnClick()
  229. if ( GetCurrentMapZone() ~= 0 ) then
  230. SetMapZoom(GetCurrentMapContinent());
  231. else
  232. SetMapZoom(0);
  233. end
  234. end
  235. function WorldMap_UpdateZoneDropDownText()
  236. if ( GetCurrentMapZone() == 0 ) then
  237. UIDropDownMenu_ClearAll(WorldMapZoneDropDown);
  238. else
  239. UIDropDownMenu_SetSelectedID(WorldMapZoneDropDown, GetCurrentMapZone());
  240. end
  241. end
  242. function WorldMap_UpdateContinentDropDownText()
  243. if ( GetCurrentMapContinent() == 0 ) then
  244. UIDropDownMenu_ClearAll(WorldMapContinentDropDown);
  245. else
  246. UIDropDownMenu_SetSelectedID(WorldMapContinentDropDown,GetCurrentMapContinent());
  247. end
  248. end
  249. function WorldMapButton_OnClick(mouseButton, button)
  250. CloseDropDownMenus();
  251. if ( mouseButton == "LeftButton" ) then
  252. if ( not button ) then
  253. button = this;
  254. end
  255. local x, y = GetCursorPosition();
  256. x = x / button:GetEffectiveScale();
  257. y = y / button:GetEffectiveScale();
  258. local centerX, centerY = button:GetCenter();
  259. local width = button:GetWidth();
  260. local height = button:GetHeight();
  261. local adjustedY = (centerY + (height/2) - y) / height;
  262. local adjustedX = (x - (centerX - (width/2))) / width;
  263. ProcessMapClick( adjustedX, adjustedY);
  264. else
  265. WorldMapZoomOutButton_OnClick();
  266. end
  267. end
  268. function WorldMapButton_OnUpdate(elapsed)
  269. local x, y = GetCursorPosition();
  270. x = x / this:GetEffectiveScale();
  271. y = y / this:GetEffectiveScale();
  272. local centerX, centerY = this:GetCenter();
  273. local width = this:GetWidth();
  274. local height = this:GetHeight();
  275. local adjustedY = (centerY + (height/2) - y ) / height;
  276. local adjustedX = (x - (centerX - (width/2))) / width;
  277. local name, fileName, texPercentageX, texPercentageY, textureX, textureY, scrollChildX, scrollChildY = UpdateMapHighlight( adjustedX, adjustedY );
  278. WorldMapFrame.areaName = name;
  279. if ( not WorldMapFrame.poiHighlight ) then
  280. WorldMapFrameAreaLabel:SetText(name);
  281. end
  282. if ( fileName ) then
  283. WorldMapHighlight:SetTexCoord(0, texPercentageX, 0, texPercentageY);
  284. WorldMapHighlight:SetTexture("Interface\\WorldMap\\"..fileName.."\\"..fileName.."Highlight");
  285. textureX = textureX * width;
  286. textureY = textureY * height;
  287. scrollChildX = scrollChildX * width;
  288. scrollChildY = -scrollChildY * height;
  289. if ( (textureX > 0) and (textureY > 0) ) then
  290. WorldMapHighlight:SetWidth(textureX);
  291. WorldMapHighlight:SetHeight(textureY);
  292. WorldMapHighlight:SetPoint("TOPLEFT", "WorldMapDetailFrame", "TOPLEFT", scrollChildX, scrollChildY);
  293. WorldMapHighlight:Show();
  294. --WorldMapFrameAreaLabel:SetPoint("TOP", "WorldMapHighlight", "TOP", 0, 0);
  295. end
  296. else
  297. WorldMapHighlight:Hide();
  298. end
  299. --Position player
  300. UpdateWorldMapArrowFrames();
  301. local playerX, playerY = GetPlayerMapPosition("player");
  302. if ( playerX == 0 and playerY == 0 ) then
  303. ShowWorldMapArrowFrame(nil);
  304. WorldMapPing:Hide();
  305. else
  306. playerX = playerX * WorldMapDetailFrame:GetWidth();
  307. playerY = -playerY * WorldMapDetailFrame:GetHeight();
  308. PositionWorldMapArrowFrame("CENTER", "WorldMapDetailFrame", "TOPLEFT", playerX, playerY);
  309. ShowWorldMapArrowFrame(1);
  310. -- Position clear button to detect mouseovers
  311. WorldMapPlayer:SetPoint("CENTER", "WorldMapDetailFrame", "TOPLEFT", playerX, playerY);
  312. -- Position player ping if its shown
  313. if ( WorldMapPing:IsVisible() ) then
  314. WorldMapPing:SetPoint("CENTER", "WorldMapDetailFrame", "TOPLEFT", playerX-7, playerY-9);
  315. -- If ping has a timer greater than 0 count it down, otherwise fade it out
  316. if ( WorldMapPing.timer > 0 ) then
  317. WorldMapPing.timer = WorldMapPing.timer - elapsed;
  318. if ( WorldMapPing.timer <= 0 ) then
  319. WorldMapPing.fadeOut = 1;
  320. WorldMapPing.fadeOutTimer = MINIMAPPING_FADE_TIMER;
  321. end
  322. elseif ( WorldMapPing.fadeOut ) then
  323. WorldMapPing.fadeOutTimer = WorldMapPing.fadeOutTimer - elapsed;
  324. if ( WorldMapPing.fadeOutTimer > 0 ) then
  325. WorldMapPing:SetAlpha(255 * (WorldMapPing.fadeOutTimer/MINIMAPPING_FADE_TIMER))
  326. else
  327. WorldMapPing.fadeOut = nil;
  328. WorldMapPing:Hide();
  329. end
  330. end
  331. end
  332. end
  333. --Position groupmates
  334. local partyX, partyY, partyMemberFrame;
  335. local playerCount = 0;
  336. if ( GetNumRaidMembers() > 0 ) then
  337. for i=1, MAX_PARTY_MEMBERS do
  338. partyMemberFrame = getglobal("WorldMapParty"..i);
  339. partyMemberFrame:Hide();
  340. end
  341. for i=1, MAX_RAID_MEMBERS do
  342. local unit = "raid"..i;
  343. partyX, partyY = GetPlayerMapPosition(unit);
  344. partyMemberFrame = getglobal("WorldMapRaid"..playerCount + 1);
  345. if ( (partyX ~= 0 or partyY ~= 0) and not UnitIsUnit(unit, "player") ) then
  346. partyX = partyX * WorldMapDetailFrame:GetWidth();
  347. partyY = -partyY * WorldMapDetailFrame:GetHeight();
  348. partyMemberFrame:SetPoint("CENTER", "WorldMapDetailFrame", "TOPLEFT", partyX, partyY);
  349. partyMemberFrame.name = nil;
  350. partyMemberFrame.unit = unit;
  351. partyMemberFrame:Show();
  352. playerCount = playerCount + 1;
  353. end
  354. end
  355. else
  356. for i=1, MAX_PARTY_MEMBERS do
  357. partyX, partyY = GetPlayerMapPosition("party"..i);
  358. partyMemberFrame = getglobal("WorldMapParty"..i);
  359. if ( partyX == 0 and partyY == 0 ) then
  360. partyMemberFrame:Hide();
  361. else
  362. partyX = partyX * WorldMapDetailFrame:GetWidth();
  363. partyY = -partyY * WorldMapDetailFrame:GetHeight();
  364. partyMemberFrame:SetPoint("CENTER", "WorldMapDetailFrame", "TOPLEFT", partyX, partyY);
  365. partyMemberFrame:Show();
  366. end
  367. end
  368. end
  369. -- Position Team Members
  370. local numTeamMembers = GetNumBattlefieldPositions();
  371. for i=playerCount+1, MAX_RAID_MEMBERS do
  372. partyX, partyY, name = GetBattlefieldPosition(i - playerCount);
  373. partyMemberFrame = getglobal("WorldMapRaid"..i);
  374. if ( partyX == 0 and partyY == 0 ) then
  375. partyMemberFrame:Hide();
  376. else
  377. partyX = partyX * WorldMapDetailFrame:GetWidth();
  378. partyY = -partyY * WorldMapDetailFrame:GetHeight();
  379. partyMemberFrame:SetPoint("CENTER", "WorldMapDetailFrame", "TOPLEFT", partyX, partyY);
  380. partyMemberFrame.name = name;
  381. partyMemberFrame:Show();
  382. end
  383. end
  384. -- Position flags
  385. local flagX, flagY, flagToken, flagFrame, flagTexture;
  386. local numFlags = GetNumBattlefieldFlagPositions();
  387. for i=1, numFlags do
  388. flagX, flagY, flagToken = GetBattlefieldFlagPosition(i);
  389. flagFrame = getglobal("WorldMapFlag"..i);
  390. flagTexture = getglobal("WorldMapFlag"..i.."Texture");
  391. if ( flagX == 0 and flagY == 0 ) then
  392. flagFrame:Hide();
  393. else
  394. flagX = flagX * WorldMapDetailFrame:GetWidth();
  395. flagY = -flagY * WorldMapDetailFrame:GetHeight();
  396. flagFrame:SetPoint("CENTER", "WorldMapDetailFrame", "TOPLEFT", flagX, flagY);
  397. flagTexture:SetTexture("Interface\\WorldStateFrame\\"..flagToken);
  398. flagFrame:Show();
  399. end
  400. end
  401. for i=numFlags+1, NUM_WORLDMAP_FLAGS do
  402. flagFrame = getglobal("WorldMapFlag"..i);
  403. flagFrame:Hide();
  404. end
  405. -- Position corpse
  406. local corpseX, corpseY = GetCorpseMapPosition();
  407. if ( corpseX == 0 and corpseY == 0 ) then
  408. WorldMapCorpse:Hide();
  409. else
  410. corpseX = corpseX * WorldMapDetailFrame:GetWidth();
  411. corpseY = -corpseY * WorldMapDetailFrame:GetHeight();
  412. WorldMapCorpse:SetPoint("CENTER", "WorldMapDetailFrame", "TOPLEFT", corpseX, corpseY);
  413. WorldMapCorpse:Show();
  414. end
  415. end
  416. function WorldMapUnit_OnEnter()
  417. -- Adjust the tooltip based on which side the unit button is on
  418. local x, y = this:GetCenter();
  419. local parentX, parentY = this:GetParent():GetCenter();
  420. if ( x > parentX ) then
  421. WorldMapTooltip:SetOwner(this, "ANCHOR_LEFT");
  422. else
  423. WorldMapTooltip:SetOwner(this, "ANCHOR_RIGHT");
  424. end
  425. -- See which POI's are in the same region and include their names in the tooltip
  426. local unitButton;
  427. local newLineString = "";
  428. local tooltipText = "";
  429. -- Check player
  430. if ( MouseIsOver(WorldMapPlayer) ) then
  431. tooltipText = UnitName(WorldMapPlayer.unit);
  432. newLineString = "\n";
  433. end
  434. -- Check party
  435. for i=1, MAX_PARTY_MEMBERS do
  436. unitButton = getglobal("WorldMapParty"..i);
  437. if ( unitButton:IsVisible() and MouseIsOver(unitButton) ) then
  438. tooltipText = tooltipText..newLineString..UnitName(unitButton.unit);
  439. newLineString = "\n";
  440. end
  441. end
  442. --Check Raid
  443. for i=1, MAX_RAID_MEMBERS do
  444. unitButton = getglobal("WorldMapRaid"..i);
  445. if ( unitButton:IsVisible() and MouseIsOver(unitButton) ) then
  446. -- Handle players not in your raid or party, but on your team
  447. if ( unitButton.name ) then
  448. tooltipText = tooltipText..newLineString..unitButton.name;
  449. else
  450. tooltipText = tooltipText..newLineString..UnitName(unitButton.unit);
  451. end
  452. newLineString = "\n";
  453. end
  454. end
  455. WorldMapTooltip:SetText(tooltipText);
  456. WorldMapTooltip:Show();
  457. end
  458. function WorldMapFrame_PingPlayerPosition()
  459. WorldMapPing:SetAlpha(255);
  460. WorldMapPing:Show();
  461. --PlaySound("MapPing");
  462. WorldMapPing.timer = 1;
  463. end
  464. function ToggleWorldMap()
  465. if ( WorldMapFrame:IsVisible() ) then
  466. HideUIPanel(WorldMapFrame);
  467. else
  468. ShowUIPanel(WorldMapFrame);
  469. end
  470. end